﻿using System;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using HiauPdm.Bll;
using HiauPdm.Web;

namespace HiauPdm.Web
{
    public partial class WgjXzMain : PageBase
    {
        protected override bool IsAccess()
        {
            return true;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BtnFind.OnClientClick = "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(BtnFind, null) + ";return false;";
                TextWhere.Attributes["onkeydown"] = "if(event.keyCode==13){document.getElementById('" + BtnFind.ClientID + "').click();}";
                if ((Request.QueryString["WgjlbBh"] != null) && (Request.QueryString["WgjlbBh"].Trim() != string.Empty))
                {
                    TextWhere.Text = "FindByWgjDh|" + Request.QueryString["WgjlbBh"].Trim();
                    BtnFind_Click(BtnFind, null);
                }
                TextWhere.Focus();
            }
        }

        protected void BtnFind_Click(object sender, EventArgs e)
        {
            if (TextWhere.Text.Trim() != string.Empty)
            {
                string sWgjDh = string.Empty;
                if (TextWhere.Text.IndexOf("FindByWgjDh|") == 0)
                {
                    sWgjDh = TextWhere.Text.Substring(12);
                    TextWhere.Text = string.Empty;
                }
                DataSet ds = BWgjCx.QueryWgj(TextWhere.Text.Trim(), sWgjDh);
                GridWgj.DataSource = ds;
                GridWgj.DataBind();
            }
            TextWhere.Text = string.Empty;
            TextWhere.Focus();
        }

        protected void GridWgj_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((CheckBox)e.Row.Cells[0].Controls[1]).Attributes["onclick"] = "this.checked=!this.checked;";
                e.Row.Attributes["onclick"] = "SetWgj(this,'" + e.Row.Cells[0].Controls[1].ClientID + "','" + TextWhere.ClientID + "');";
                e.Row.Attributes["ondblclick"] = "SetWgjResult(this);";
            }
        }
    }
}